<?php

/*
@版本日期: 2011年8月22日
@著作权所有: 1024 intelligence ( http://www.1024i.com )

获得使用本类库的许可, 您必须保留著作权声明信息.
报告漏洞，意见或建议, 请联系 Lou Barnes(iua1024@gmail.com)
*/
require_once BONE_ROOT.DS.'libs'.DS.'http'.DS.'http_handler.php';

class lib_http extends lib
{

	private $handler = null;

	// 构造函数
	public function __construct()
	{
		if( function_exists('curl_init') && function_exists('curl_exec') )
		{
			include_once BONE_ROOT.DS.'libs'.DS.'http'.DS.'http_curl.php';
			$this->handler = new lib_http_curl();
		}
		else if( function_exists('fopen') && ini_get('allow_url_fopen')==true )
		{
			include_once BONE_ROOT.DS.'libs'.DS.'http'.DS.'http_fopen.php';
			$this->handler = new lib_http_fopen();
		}
		else if ( function_exists( 'fsockopen' ) )
		{
			include_once BONE_ROOT.DS.'libs'.DS.'http'.DS.'http_fsockopen.php';
			$this->handler = new lib_http_fsockopen();
		}
		
		if($this->handler===null)
		{
			$this->set_error('您的服务器没有安装可用于HTTP通信的扩展');
			return false;
		}
	}


	// 析构函数
	public function __destruct(){}


	public function get($url)
	{
		$this->handler->set_url($url);
		return $this->handler->request();
	}

	public function post($url, $datas)
	{
		$this->handler->set_url($url);
		$this->handler->set_header('method', 'POST');
		
		if($datas!==null)
		{
			foreach($datas as $key=>$val)
			{ 
				$this->handler->set_data($key, $val);
			}
		}
		return $this->handler->request();
	}

}
?>